import { randomColor, getRandom } from "../util/randomColor";
var divContainer = document.getElementById("divContainer");
var divCenter = document.getElementById("divCenter");

export default function (n, isPrime) {
  var span = document.createElement("span");
  var color = "#000";
  if (isPrime) {
    color = randomColor();
    span.style.color = color;
  }
  span.innerText = n;
  divContainer.appendChild(span);
  createCenterNum(n, color);
}

function createCenterNum(n, color) {
  // 新产生一个 div
  var div = document.createElement("div");
  div.className = "center";
  div.innerText = n;
  div.style.color = color;
  document.body.appendChild(div);
  getComputedStyle(div).left; // reflow 重排
  div.style.transform = `translate(${getRandom(-150, 150)}px, ${getRandom(
    -150,
    150
  )}px)`;
  div.style.opacity = 0;
}
